<%
/**
 * fourth wizard page / tab
 *
 * @author	Jeroen Wesbeek <work@osx.eu>
 * @package AjaxFlow
 */
%>
<script type="text/javascript" >

	$(document).ready(function(){

			
		loadInterviewFolders();
		var  progress = $('myprogress').progressbar();

	});

	function loadInterviewFolders(){
		
	var interviewId = "${interview?.id}";
	${remoteFunction(
		action:'loadInterviewFolders',
		type:'POST',
		update: [success: 'listInterviewFolders', failure: 'get'],
		params:'\'interviewId=\'+interviewId'
								
	)}

	}

function show_files(folder_id,orderby){
			
	var interviewId = "${interview?.id}";
	
		${remoteFunction(
				action:'filesInFolder',
				type:'POST',
				onLoading:'spinPage(true);',
				onComplete:'spinPage(false)',
				update: [success: 'listInterviewFiles', failure: 'daImp'],
				params:'\'folderId=\' + folder_id + \'&order_by=\' + orderby + \'&iId=\' + interviewId',
				
		)}
		loadFilesNumber();
	}


	function pleaseWait(){
		$("#btnUpload").button('loading');
		$('#progressBox').fadeIn();
		$('#btnUpload').prop('disabled', true);
		$('#upCloseBtn').prop('disabled', true);
		$('#exampleInputFile1').prop('disabled',true);
		$('#comments').prop('disabled',true);
	
	}
	function resetafterUp(){
		$('#progressBox').hide();
		$("#btnUpload").button('reset');
		$('#upCloseBtn').prop('disabled', false);
		$('#btnUpload').prop('disabled', false);
		$('#myprogress').attr('aria-valuenow', 0);
        $('#myprogress').css('width', 0 + '%');
        $('#exampleInputFile1').prop('disabled',false);
        $('#comments').prop('disabled',false);
	}

	function spinPage(onoff){

		if(onoff){
			$('#spinPage').fadeIn();
		
		}else{
			$('#spinPage').fadeOut();
		}
	
	}

function fileCancelAlert(idFile,idIntervista,folderId){
		
		$.SmartMessageBox({
			title : "<div class='row'><div class='col-md-2'><i class='fa '></i></div><div class='col-md-10'>Sei Sicuro di voler eliminare questo file dai documenti dell'intervista?</div>",
			content : "<div class='col-md-2'></div><div class='col-md-10'> <BR/><BR/></div></div>",
			buttons:"[Si],[No]",
			sound:false
		}, function(ButtonPressed, Value) {
			if (ButtonPressed === "No") {
				
			}
			if (ButtonPressed === "Si") {
				${remoteFunction(asynchronous: true,
	 					action:'deleteIntervistaFile',
						params:'\'id=\' + idFile + \'&id_intervista=\' + idIntervista',
						update:[success:'filesList',failure:'filesList'],
						onFailure:'failureLoadPage(XMLHttpRequest,textStatus,errorThrown)',
						onLoading:'spinPage(true);',
						onComplete:'spinPage(false);',
						onSuccess:'show_files(folderId,"date");succcessAction(data,textStatus)'
						
				)} 
			}
			});
	}

function failureLoadPage(a,b,c){
	$.smallBox({
		title : a.responseText,
		color : "#3F8DBF",
		sound:false,
		timeout: 3000
	});

}
function showCancelResponse(a,b,c){
	
	$.smallBox({
		title : a.responseText,
		color : "#3F8DBF",
		sound:false,
		timeout: 3000
	});
	
	
}

function succcessAction(a,b){
	
	$.smallBox({
		title : a,
		color : "#3F8DBF",
		sound:false,
		timeout: 3000
	});

}
function successAdd(text){

	$('#docTypeTxt').val('');
	$('#btn_add').button('reset');
	
	$('#failureAdd').fadeOut();
	
	$.smallBox({
		title : text,
		color : "#3F8DBF",
		sound:true,
		timeout: 3000
	});
	$('#addFolderModal').modal('hide');
}
function failAdd(){

	$('#btn_add').button('reset');
	$('#failureAdd').fadeIn();
	
}

function showfDetails(fileId){

	${remoteFunction(
		action:'showInterviewFileDetail',
		type:'POST',
		update: [success: 'file_d', failure: 'get'],
	  	params: '\'fileId=\' + fileId',
		onSuccess:'spin(fileId,false);$("#fd_modal").modal()',
		onLoading:'spin(fileId,true);',
		onFailure:'showCancelResponse(XMLHttpRequest,textStatus,errorThrown)',
		onComplete:'spin(fileId,false)'
	)}

	

}
function spin(fileId,onoff){

	if(onoff){
		$('#spin_'+fileId).fadeIn();
	}else{
		$('#spin_'+fileId).fadeOut();
	}

}
function successUpload(data){

	$.smallBox({
		title : data,
		color : "#3F8DBF",
		sound:false,
		timeout: 3000
	});
	
}
function failureUpload(a,b,c){
	
	$.smallBox({
		title : a.responseText,
		color : "#3F8DBF",
		sound:false,
		timeout: 3000
	});

}

function folderCancelAlert(idFolder,interId){
	$.SmartMessageBox({
		title : "<div class='row'><div class='col-md-2'><i class='fa '></i></div><div class='col-md-10'>Sei Sicuro di voler eliminare questa cartella e tutti i file contenuti?</div>",
		content : "<div class='col-md-2'></div><div class='col-md-10'> <BR/><BR/></div></div>",
		buttons:"[Si],[No]",
		sound:false
	}, function(ButtonPressed, Value) {
		if (ButtonPressed === "No") {
			
		}
		if (ButtonPressed === "Si") {
			${remoteFunction(asynchronous: true,
 					action:'deleteInterviewFolder',
					
					onLoading:'spinPage(true);',
					onComplete:'spinPage(false)',
					params:'\'folderId=\' + idFolder + \'&interviewId=\' + interId',
					update:[success:'listInterviewFolders'],	
					onSuccess:'emptyFileList();successAdd("Cartella Eliminata correttamente")',
					onFailure:'failureLoadPage(XMLHttpRequest,textStatus,errorThrown)'
					)} 
		}
		});
}
	function  emptyFileList(){
		$('#listInterviewFiles').empty();

	}

	
	function failureLoadPage(a,b,c){
		$.smallBox({
			title : a.responseText,
			color : "#a90329",
			sound:true,
			timeout: 3000
		});

	}

	function showUpPopUp(){

		var interviewId = "${interview?.id}";
		
		${remoteFunction(asynchronous: true,

			action:'showUploadpopup',
			onLoading:'spinPage(true);',
			onComplete:'spinPage(false)',
			params: '\'interviewId=\' + interviewId',
			update:[success:'uploadpp'],	
			onSuccess:'$("#fileInterviewUpload_modal").modal()',
			onFailure:'failureLoadPage(XMLHttpRequest,textStatus,errorThrown)'
			)}
	



		}
	
	
</script>
<af:page>
<div class="alert alert-danger fade in" id="validity_label"></div>
<div id="content">

<div class="row">
	
	<div class="col-xs-10 col-sm-6 col-md-6 col-lg-6 pull-right" >
				
		<g:if test="${interview}">
					
			<h3 class="pull-right">Intervista : <exdutility:number_interview value="${interview?.id }"/></h3>
					
		</g:if>
			
			
	</div>

</div>

<%--Interview doc TABS inizio rows--%>

<div class="row">

<%--	Interview doc TABS header--%>
			<ul id="myTab1" class="nav nav-tabs bordered">
				<li class="active">
				<a href="#tabDoc" data-toggle="tab"><i class="fa fa-fw fa-2x fa-file-pdf-o"></i>Documenti
						
				</a>
				</li>
				<li>
					<a href="#tabEvents" data-toggle="tab"><i class="fa fa-fw fa-2x fa-calendar"></i> Eventi
					</a>
				</li>
				
			</ul>

<%--Interview doc TABS contenuto--%>
	
	<div id="myTabContent1" class="tab-content padding-10">
<%--		tab document start--%>
		<div class="tab-pane fade in active" id="tabDoc">
			
			<div class="row">

					<div class="col-xs-10 col-sm-6 col-md-6 col-lg-6" >
					
						<input type="hidden" name="interviewId" id="interviewId" value="${interview?.id }" />
						<sec:ifNotGranted roles="ROLE_AVV">
						<h1>Inserisci i Documenti da associare all'intervista</h1>
					
			<%--		<button type="button" class="btn btn-default" data-toggle="modal" data-target="#fileInterviewUpload_modal">--%>
			<%--				Aggiungi un file--%>
			<%--		</button>--%>
						<button type="button" onclick="showUpPopUp()" class="btn btn-default" data-toggle="modal" >
								Aggiungi un file
						</button>
					
						<button type="button" class="btn btn-default" data-toggle="modal" data-target="#addFolderModal">
								Aggiungi una cartella
						</button>
						
							<i id="spinPage" class="fa fa-gear fa-2x fa-spin" style="display:none"></i>
						</sec:ifNotGranted>
					</div>
		
<%--				<div class="col-xs-10 col-sm-6 col-md-6 col-lg-6" >--%>
<%--				--%>
<%--					<g:if test="${interview}">--%>
<%--					--%>
<%--						<h3 class="pull-right">Intervista : <exdutility:number_interview value="${interview?.id }"/></h3>--%>
<%--					--%>
<%--					</g:if>--%>
<%--			--%>
<%--			--%>
<%--				</div>--%>

		</div>
		<br>
<div class="row" >
	
	<div class="col col-md-4" id="listInterviewFolders" >
			
			
			
			
	</div>
	
	<div class="col col-md-5 col-md-offset-1" id="listInterviewFiles" >
			
			
			
			
	</div>
	
</div>
		
		
	
	
			
												
</div>
<%--		tab document end--%>
		<div class="tab-pane fade" id="tabEvents">
			contenuto eventi
		</div>
			
	</div>



<%--Interview doc TABS contenuto--%>
	
	



<%--Interview doc TABS tabs doc fine--%>
</div>

<%--Interview doc TABS FINE rows--%>


</div>
<div id ="uploadpp">
		
<%--			<g:render template="/_common/modals/fileInterviewUpload" model="[interviewId:interview?.id]"></g:render>--%>
	
	</div>
	<br><br>
		<g:render template="/_common/modals/add_folder" model="[interview:interview]"></g:render>
	
	<div id="file_d">
		<g:render template="/_common/modals/intFileDetailPUp" model="[interviewId:interview?.id]" ></g:render>
	</div>
	
	
	
	

<div style="border-top: 2px solid #006DBA; padding-top: 2px;"></div>
</af:page>

